package com.wg.user.util;

import jodd.util.StringUtil;

public final class MyMd5 {

    public static String get(String input) {
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            byte[] array = md.digest(input.getBytes());
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < array.length; ++i) {
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
            }
            return sb.toString();
        } catch (java.security.NoSuchAlgorithmException e) {
            e.fillInStackTrace();
            return null;
        }
    }

    public static Boolean compare(String input, String md5) {
        String inputMd5 = MyMd5.get(input);
        return StringUtil.isNotEmpty(inputMd5) && inputMd5.equals(md5);
    }
}
